package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.ScardDao;
import com.qfedu.stussm.entity.Scard;
import com.qfedu.stussm.entity.Student;
import com.qfedu.stussm.service.intf.ScardService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/***
 *  .--,       .--,
 * ( (  .---./  ) )
 *  '.__/o   o\__.'
 *     {=  ^  =}
 *      >  -  <
 *     /       
 *    //       \
 *   //|   .   |\
 *   "'       /'"_.-~^`'-.
 *        _  /--'         `
 *    ___)( )(___
 *   (((__) (__)))    高山仰止,景行行止.虽不能至,心向往之。
 */
@Service
public class ScardServiceImpl implements ScardService {
    @Autowired
    private ScardDao dao;
    //添加
    @Override
    public int add(Scard scard) {
        return dao.add(scard);
    }
    //查询
    @Override
    public List<PageBeanVo> selectAll() {
        return dao.selectAll();
    }
    //模糊查询
    @Override
    public PageBeanVo queryPage(String stu_name, int page, int limit) {
        //1.开启分页
        PageHelper.startPage(page,limit);
        //2.PageInfo name="" name=null
        if(stu_name!=null && stu_name.length()>0){
            stu_name="%"+stu_name+"%";
        }else {
            stu_name=null;
        }
        PageInfo<Scard> pageInfo=new PageInfo<>(dao.selectLikeAll(stu_name));
        //3.返回
        return new PageBeanVo(pageInfo.getTotal(),pageInfo.getList());
    }
    //修改
    @Override
    public R update(Scard scard) {
        if(dao.update(scard)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }
    //删除
    @Override
    public R del(int id) {
        if(dao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

}
